package com.audaque.springboot.foshanupload.web.webdemo.model.domain;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class OuterClass  implements Serializable {
    private static final long serialVersionUID = 1L;
    private int outerVar = 10;
    public void outerMethod() throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
        System.out.println("Outer Method");
        // 局部内部类
        @Data
        @NoArgsConstructor
        @AllArgsConstructor
        class LocalInnerClass {
            private int localVar = 30;

            public void localMethod() {
                System.out.println("Local Inner Method");
                System.out.println("Accessing outerVar: " + outerVar);
                System.out.println("Accessing localVar: " + localVar);
            }
        }
        Class<LocalInnerClass> clazz = LocalInnerClass.class;
        //com.audaque.springboot.foshanupload.web.webdemo.model.domain.OuterClass$1LocalInnerClass
        String name = clazz.getName();
        String canonicalName = clazz.getCanonicalName();
        String simpleName = clazz.getSimpleName();

        Object localInnerObj = new LocalInnerClass();
        Method localInnerMethod = clazz.getDeclaredMethod("localMethod");
        localInnerMethod.setAccessible(true);
        localInnerMethod.invoke(localInnerObj);
        // 匿名内部类
        Runnable runnable = new Runnable() {
            @Override
            public void run() {
                System.out.println("Anonymous Inner Class");
            }
        };

        Thread thread = new Thread(runnable);
        thread.start();
    }
    // 实例内部类
    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    public  class MemberInstanceInnerClass {
        private int innerVar = 20;

        public void innerMethod() {
            System.out.println("Member Inner Method");
            System.out.println("Accessing outerVar: " + outerVar);
            System.out.println("Accessing innerVar: " + innerVar);
        }
    }
    // 静态内部类
    static class MemberStaticInnerClass {
        public void staticInnerMethod() {
            System.out.println("Static Inner Method");
        }
    }
}